package org.goobs.logic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashSet;


public class FirstOrderLogicEngine extends LogicEngine{
	
	private static HashSet <Symbol> validSymbols = new HashSet <Symbol> ();
	
	static{
		validSymbols.add(Symbol.AND);
		validSymbols.add(Symbol.OR);
		validSymbols.add(Symbol.NOT);
		validSymbols.add(Symbol.FORALL);
		validSymbols.add(Symbol.EXISTS);
		validSymbols.add(Symbol.COND);
		validSymbols.add(Symbol.BICOND);
		validSymbols.add(Symbol.EQUALS);
	}
	
	public static Collection <Symbol> validSymbols(){
		return validSymbols;
	}
	
	
	
	
	public FirstOrderLogicEngine(){
		
	}

	@Override
	public boolean evaluate(String statement) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void inform(String statement) {
		WellFormedFormula expr = new WellFormedFormula(statement, validSymbols());
		System.out.println("registering: " + expr);
		register(expr);
	}
	
	private void register(WellFormedFormula expr){
		switch(expr.getType()){
		
		}
	}
	

	@Override
	public String query(String expression) {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	private static String read(InputStream in){
		BufferedReader reader = new BufferedReader (new InputStreamReader (in));
		try {
			return reader.readLine();
		} catch (IOException e) {
			throw new IllegalStateException("could not access keyboard");
		}
	}
	
	
	
	private void cmdLine(){
		while(true){
			System.out.print("fol> ");
			try{
				this.inform(read(System.in));
			}catch(IllegalArgumentException e){
				System.err.println("ERROR: " + e.getMessage());
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e1) {	}
			}
			System.out.println();
		}
	}
	
	public static void main(String[] args){
		FirstOrderLogicEngine engine = new FirstOrderLogicEngine();
		engine.cmdLine();
		// (_exists x (_forall y       (_cond     (_bicond (p1 x) (_and (p2 y) (_or (p3 y) (p3 x))) )        (Blue sky))      ))
		
//		Symbol sym = Symbol.parse("_AND");
//		System.out.println(validSymbols.contains(sym));

	}
	
}
